#!/bin/sh

cp build/libexample.so /tmp/libexample.so

sudo gdb -n -q -batch \
    -ex "attach $(pidof qemu-system-x86_64)" \
    -ex "set \$dlopen = (void*(*)(char*, int)) dlopen" \
    -ex "set \$dlclose = (int(*)(void*)) dlclose" \
    -ex "set \$dlerror = (char*(*)(void)) dlerror" \
    -ex "set \$library = \$dlopen(\"/tmp/libexample.so\", 1)" \
    -ex "p \$library ? \"Injection successful!\" : \"Injection failed!\"" \
    -ex "call \$library ? \$dlclose(\$library) : \$dlerror()" \
    -ex "detach" \
    -ex "quit"

